<template>
  <a-drawer
    :title="title"
    :closable="false"
    :maskClosable="true"
    :width="500"
    :visible="visible"
    :confirmLoading="confirmLoading"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :md="24" :sm="24" v-for="item in scoredList" :key="item.id">
            <a-form-item :label="item.itemName" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <label>{{ item.itemScore }}</label>
              <label style="margin-left: 20px">满分：{{ item.itemFullScore }}</label>
            </a-form-item>
          </a-col>
          <a-col :md="24" :sm="24">
            <a-form-item label="总分" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <label>{{ totalScored }}</label>
              <label style="margin-left: 20px">满分：{{ totalScore }}</label>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <div class="drawer-footer">
      <a-button class="left" @click="handleCancel"> 关闭</a-button>
    </div>
  </a-drawer>
</template>

<script>
  import { scoreRecordsList } from '@/api/modular/main/scoreRecordsManage'

  export default {
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        id: undefined,
        title: '',
        visible: false,
        confirmLoading: false,
        category: null,
        form: this.$form.createForm(this),
        scoreList: [],
        scoredList: [],
        tempList: []
      }
    },
    computed: {
      totalScore() {
        if (this.scoredList.length === 0) return 0
        return this.scoredList.reduce((prev, current) => prev + current.itemFullScore, 0)
      },
      totalScored() {
        if (this.scoredList.length === 0) return 0
        return this.scoredList.map(item => item.itemScore).reduce((sum, item) => sum + item)
      }
    },
    methods: {
      // 初始化方法
      open(courseSelectionId, category) {
        this.confirmLoading = true
        this.title = category === 0 ? '项目打分' : '答辩打分'
        this.category = category
        this.loadScoreRecordsList(courseSelectionId, category)
        this.visible = true
        this.confirmLoading = false
      },
      loadScoreRecordsList(courseSelectionId, category) {
        scoreRecordsList({
          courseSelectionId: courseSelectionId,
          category: category
        }).then((res) => {
          if (res.success) {
            this.scoredList = res.data
          }
        })
      },
      handleCancel() {
        this.form.resetFields()
        this.visible = false
        this.scoredList = []
      }
    }
  }
</script>

<style lang="less" scoped>
</style>
